#ifndef YOOHOO_XMPPCORE_NEGOTIANT_H
#define YOOHOO_XMPPCORE_NEGOTIANT_H

#include <QtCore/QObject>

namespace yoohoo_xmppcore {

class Connector;
class StreamFeature;
class StreamFeatures;

class Negotiant : public QObject {
	Q_OBJECT
public:
	enum NegotiationState {
		None,
		InitialStreamSent,
		InitialStreamReceived,
		StreamFeaturesReceived,
		NogotiationDone
	};
	enum NegotiationError {
		UnknownNegotiationProtocolError,
		UnknownNegotiationHostError
	};
	Negotiant(Connector* connector, QObject* parent = 0);
	~Negotiant();
	virtual void negotiate();
	StreamFeatures* streamFeatures();
	void registerStreamFeature(StreamFeature* streamFeature);

signals:
	void done(StreamFeatures* streamFeatures);
	void negotiationError(Negotiant::NegotiationError error);
	void written(QString xml);

protected slots:
	virtual void connectorReceived(QString xml);

protected:
	void sendIntialStream();
	void processStreamFeatures(QString& xml);
	void processInitialStream(QString& xml);
	void write(const QString& xml);

protected:
	StreamFeatures* _streamFeatures;
	Connector* _connector;
	NegotiationState _negotiationState;

};

}

#endif

